﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace moveErrorFile.classes
{
    class clsLogHelper
    {
        public static void writeLog(out string sErrorMsg, string sLogMsg, bool bToLogInd)
        {
            sErrorMsg = null;
            string m_exePath = string.Empty;
            StackFrame caller = (new System.Diagnostics.StackTrace()).GetFrame(0);

            m_exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            try
            {
                string sToday = DateTime.Today.Date.Year.ToString() + DateTime.Today.Date.Month.ToString() + DateTime.Today.Date.Day.ToString();
                string sFileName = sToday + "_log.txt";

                if (!File.Exists(m_exePath + sFileName))
                    File.Create(m_exePath + sFileName);

                using (StreamWriter writer = File.AppendText(m_exePath + "\\" + sFileName))
                {
                    try
                    {
                        writer.Write("\r\nLog Entry " + caller.GetMethod().Name + " : ");
                        writer.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
                            DateTime.Now.ToLongDateString());
                        writer.WriteLine("  :");
                        writer.WriteLine("  :{0}", sLogMsg);
                        writer.WriteLine("-------------------------------");
                        
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                sErrorMsg = ex.Message;
            }
        }

    }
}
